;
! function() {
	var $ = layui.jquery,
		layer = layui.layer,
		form = layui.form;

	refCode();

	// 点击刷新验证码
	$("#addAdmin_code_img").on("click", function() {
		refCode();
	});

	// 获取验证码
	function refCode() {
		$.ajax({
			url: "/secadminuser/getPictureVerificationCode",
			success: function(result) {
				$("#addAdmin_code_img").prop("src",
					"data:image/jpg;base64," + result.image);
			}
		});
	}

	// 自定义表单验证
	form.verify({
		code: function(value) {
			if(value.length < 6) {
				return "验证码长度不能少于6位";
			}
		},
		email: function(value){
			var regEmail = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
			if (!regEmail.test(value)) {
				return "邮箱格式有误";
			}
		}
	});

	form.on("submit(addContact)", function() {
		$.ajax({
			url: "/appsystemcontact/appSystemContact",
			type: "post",
			data: {
				"id": $("#contact-id").val(),
				"content": $("#contact-content").val(),
				"code": $("#contact-code").val(),
				"qq" : $("#contact-qq").val(),
				"email" : $("#contact-email").val(),
				"phone" : $("#contact-phone").val()
			},
			async: false,
			success: function(result) {
				layer.msg(result.msg);
				if(result.status == 0) {
					location.href='/appSystemContact';
				}else{
					$("#help-code").val("");
				}
			}
		});
		return false;
	});
}();